package com.hboxs.asl.controller.app.index;

import com.hboxs.asl.JsonMessage;
import com.hboxs.asl.controller.app.BaseController;
import com.hboxs.asl.service.RushService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by xxx on 2016/12/22
 * 限时抢购
 */
@Controller("appRushController")
@RequestMapping(value = "/app/rush")
public class RushController extends BaseController {

    @Resource(name = "rushServiceImpl")
    private RushService rushService;

    /**
     * 限时抢购
     */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public
    @ResponseBody
    Object index() {

        try {

            return JsonMessage.success(

                    JsonMessage.optimiseObj(

                            rushService.findEnableList(), "beginDate", "endDate", "product.id",

                            "product.name", "product.image", "product.price", "product.promotionPrice",

                            "product.finalScore", "product.weight", "product.sales"
                    )
            );

        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonMessage.UNKNOWN_ERROR;
    }
}
